package com.suixinsanren.design.iterator.demo03;

import java.util.ArrayList;

public class PancakeHouseMenuIterator implements Iterator<MenuItem> {

    private ArrayList<MenuItem> menuItems;
    private int position = 0;

    public PancakeHouseMenuIterator(PancakeHouseMenu pancakeHouseMenu) {
        this.menuItems = pancakeHouseMenu.getMenuItem();
    }

    @Override
    public boolean hasNext() {
        return position < menuItems.size();
    }

    @Override
    public MenuItem next() {
        return menuItems.get(position++);
    }

    @Override
    public void remove() {
        menuItems.remove(position - 1);
    }
}
